/*https://leetcode.cn/problems/longest-common-subsequence/*/
class Solution {
public:
    int longestCommonSubsequence(string text1, string text2) {
       int n = text1.size();
       int m = text2.size();
       vector<vector<int>> dp(n + 1, vector<int>(m + 1));   //dp表示以i结尾和以j结尾的最大长度
       for(int i = 1;i <= n;i++){
            char c1 = text1[i-1];
         for(int j = 1;j <= m;j++){
            char c2 = text2[j-1];
            if(c1 == c2){//当当前最末尾的字符是一致的
                dp[i][j] = dp[i-1][j-1]+1;
            }
            else{//当当前最末尾的字符不一样时，我们分为以text1结尾和以text2结尾，判断哪个的长度比较大
                dp[i][j] = max(dp[i-1][j],dp[i][j-1]);
            }
        }
       }
       return dp[n][m]; 
    }
};